package com.sx.micowell.module.help

import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.mvvm.bar.TitleBar
import com.example.mvvm.base.ContainerActivity
import com.example.mvvm.base.action.TitleBarAction
import com.example.mvvm.base.data.DataBindingConfig
import com.example.mvvm.until.LogUtils
import com.gyf.immersionbar.ImmersionBar
import com.miloyu.modelnet.response.HelpInfoVO
import com.sx.micowell.R
import com.sx.micowell.databinding.FragHelpDetailsBinding
import com.sx.micowell.framework.app.IntentKey
import com.sx.micowell.framework.app.MyFragment
import com.sx.micowell.framework.arouth.RoutePath
import com.sx.micowell.module.web.WebViewFragment

/**
 * @author: YY
 * @time: 2021/8/9
 * @describe 帮助详情
 */
@Route(path = RoutePath.HELP_DETAILS)
class HelpDetailsFragment : MyFragment<FragHelpDetailsBinding, ContainerActivity>(),
    TitleBarAction {

    @Autowired(name = IntentKey.DATA)
    @JvmField
    var helpInfoVO : HelpInfoVO? = null

    override fun initViewModel() {

    }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.frag_help_details)
    }

    override fun initView() {
        ImmersionBar.with(this).statusBarDarkFont(true)
            .fitsSystemWindows(true).init()
        binding.title.setOnTitleBarListener(this)
    }

    override fun initData() {
        LogUtils.d("initData ${helpInfoVO?.content}")
        if (helpInfoVO != null) {
            binding.tvTitle.text = helpInfoVO!!.title
            loadRootFragment(helpInfoVO!!)
        }
    }

    override fun onLeftClick(v: View?) {
        myActivity.finish()
    }


    private fun loadRootFragment(data: HelpInfoVO) {
        fragmentManager?.beginTransaction()?.add(R.id.fl_container,
            WebViewFragment.newInstance("", data.content)
        )?.commit()
    }

    override fun getTitleBar(): TitleBar? =binding.title
}